#include "stdafx.h"
#include "PreferencesUi.h"
#include "PreferencesUiImpl.h"

PreferencesUi::PreferencesUi()
	: pImpl( new PreferencesUiImpl )
{
	UVDlg = new CDialog;
}

const char *PreferencesUi::getVersion()
{
	return pImpl->getVersion();
}

//HWND PreferencesUi::createDialog( IN const char *pszSheet, HWND ParentWindow )
//{
//	return pImpl->createDialog( pszSheet, ParentWindow );
//}
//
//bool PreferencesUi::setPreferences( IN const char *pszSheet, IN const char *pszPreferences )
//{
//	return setPreferences( pszSheet, pszPreferences );
//}

bool PreferencesUi::getPreferences( IN const char *pszSheet, 
									INOUT std::string &strPreferences )
{
	return getPreferences( pszSheet, strPreferences );
}

bool PreferencesUi::onActivate( IN const char *pszSheet )
{
	return onActivate( pszSheet );
}

bool PreferencesUi::onHide( IN const char *pszSheet )
{
	return onHide( pszSheet );
}

CDialog * PreferencesUi::createDialog( IN const wchar_t *pszSheet, CWnd * ParentWindow )
{
	AFX_MANAGE_STATE(AfxGetStaticModuleState());

	std::wstring ParseType;

	ParseType = L"UV";

	if (pszSheet == ParseType)
	{
		UVDialog = new DlgUV;
		UVDialog->Create( IDD_UV_PROP_PAGE, ParentWindow);

		UVDlg = UVDialog;

		// setting up of themes on the static labels
		UVCardOptions.SubclassDlgItem( IDC_ST_UVCO_METHOD, UVDlg );
		UVCardOptions.SetPrnDrvTheme();
		UVSideOptions.SubclassDlgItem( IDC_ST_UVSO_METHOD, UVDlg );
		UVSideOptions.SetPrnDrvTheme();
		UVFront.SubclassDlgItem( IDC_ST_UVPP_FRONT, UVDlg );
		UVFront.SetFontBold(TRUE);
		UVBack.SubclassDlgItem( IDC_ST_UVPP_BACK, UVDlg );
		UVBack.SetFontBold(TRUE);

		// setting up of the seperator bars
		UVSeparator[ 0 ].SubclassDlgItem( IDC_ST_UV_SPLIT1, UVDlg );
		UVSeparator[ 1 ].SubclassDlgItem( IDC_ST_UV_SPLIT2, UVDlg );
		UVSeparator[ 2 ].SubclassDlgItem( IDC_ST_UV_SPLIT3, UVDlg );
		UVSeparator[ 3 ].SubclassDlgItem( IDC_ST_UV_SPLIT4, UVDlg );
		UVSeparator[ 4 ].SubclassDlgItem( IDC_ST_UV_SPLIT5, UVDlg );
		UVSeparator[ 5 ].SubclassDlgItem( IDC_ST_UV_SPLIT6, UVDlg );
		UVSeparator[ 6 ].SubclassDlgItem( IDC_ST_UV_SPLIT7, UVDlg );

		return UVDlg;
	}

	return 0;
}

bool PreferencesUi::setPreferences( IN const wchar_t *pszSheet)
{
	std::wstring Layout = L"uv";

	// for uv dialog
	if (pszSheet == Layout)
	{
		if(GpUV_Preferences->bUVPrintYMCUVOnSameRetransfer == TRUE)
		{
			UVDlg->CheckDlgButton(IDC_CB_UV_PRINT_YMCUV_ONSAME, BST_CHECKED);
		}

		if(GpUV_Preferences->bUVAreaFront == TRUE)
		{
			UVDlg->CheckDlgButton(IDC_CB_UV_AREA_FRONT, BST_CHECKED);
		}
		else
		{
			UVDlg->GetDlgItem(IDC_PIC_UV_AREA_FRONT)->EnableWindow(FALSE);
		}

		if(GpUV_Preferences->bUVAreaBack == TRUE)
		{
			UVDlg->CheckDlgButton(IDC_CB_UV_AREA_BACK, BST_CHECKED);
		}
		else if(GpUV_Preferences->bPrintBackSide == FALSE)
		{
			UVDlg->GetDlgItem(IDC_CB_UV_AREA_BACK)->EnableWindow(FALSE);
			UVDlg->GetDlgItem(IDC_PIC_UV_AREA_BACK)->EnableWindow(FALSE);
		}
		else
		{
			UVDlg->GetDlgItem(IDC_PIC_UV_AREA_BACK)->EnableWindow(FALSE);
		}

		if(GpUV_Preferences->bUVImageFront == TRUE)
		{
			UVDlg->CheckDlgButton(IDC_CB_UV_IMAGE_FRONT, BST_CHECKED);
			UVDlg->GetDlgItem(IDC_EF_UV_IMAGE_FRONT)->EnableWindow(TRUE);
		}
		else
		{
			UVDlg->GetDlgItem(IDC_EF_UV_IMAGE_FRONT)->EnableWindow(FALSE);
			UVDlg->GetDlgItem(IDC_PB_UV_IMAGE_FRONT)->EnableWindow(FALSE);
		}

		if(GpUV_Preferences->bUVImageBack == TRUE)
		{
			UVDlg->CheckDlgButton(IDC_CB_UV_IMAGE_BACK, BST_CHECKED);
			UVDlg->GetDlgItem(IDC_EF_UV_IMAGE_BACK)->EnableWindow(TRUE);
		}
		else if(GpUV_Preferences->bPrintBackSide == FALSE)
		{
			UVDlg->GetDlgItem(IDC_CB_UV_IMAGE_BACK)->EnableWindow(FALSE);
			UVDlg->GetDlgItem(IDC_PIC_UV_IMAGE_BACK)->EnableWindow(FALSE);
			UVDlg->GetDlgItem(IDC_PB_UV_IMAGE_BACK)->EnableWindow(FALSE);
		}
		else
		{
			UVDlg->GetDlgItem(IDC_EF_UV_IMAGE_BACK)->EnableWindow(FALSE);
			UVDlg->GetDlgItem(IDC_PB_UV_IMAGE_BACK)->EnableWindow(FALSE);
		}

		if(GpUV_Preferences->bUVFrom2ndPageFront == TRUE)
		{
			UVDlg->CheckDlgButton(IDC_CB_UV_SECOND_PAGE_FRONT, BST_CHECKED);
		}

		if(GpUV_Preferences->bUVFrom2ndPageBack == TRUE)
		{
			UVDlg->CheckDlgButton(IDC_CB_UV_SECOND_PAGE_BACK, BST_CHECKED);
		}
		else if(GpUV_Preferences->bPrintBackSide == FALSE)
		{
			UVDlg->GetDlgItem(IDC_CB_UV_SECOND_PAGE_BACK)->EnableWindow(FALSE);
		}

		if(GpUV_Preferences->bUVSecureAreaPos1Front == TRUE)
		{
			UVDlg->CheckDlgButton(IDC_RG_UV_MAC_FRONT_A, BST_CHECKED);
		}

		if(GpUV_Preferences->bUVSecureAreaPos2Front == TRUE)
		{
			UVDlg->CheckDlgButton(IDC_RG_UV_MAC_FRONT_B, BST_CHECKED);
		}

		if(GpUV_Preferences->bUVSecureAreaPos1Back == TRUE)
		{
			UVDlg->CheckDlgButton(IDC_RG_UV_MAC_BACK_A, BST_CHECKED);
		}
		else if(GpUV_Preferences->bPrintBackSide == FALSE)
		{
			UVDlg->CheckDlgButton(IDC_RG_UV_MAC_BACK_A, BST_CHECKED);	// defaulted position
			UVDlg->GetDlgItem(IDC_RG_UV_MAC_BACK_A)->EnableWindow(FALSE);
		}

		if(GpUV_Preferences->bUVSecureAreaPos2Back == TRUE)
		{
			UVDlg->CheckDlgButton(IDC_RG_UV_MAC_BACK_B, BST_CHECKED);
		}
		else if(GpUV_Preferences->bPrintBackSide == FALSE)
		{
			UVDlg->GetDlgItem(IDC_RG_UV_MAC_BACK_B)->EnableWindow(FALSE);
		}
	}

	return TRUE;
}

bool PreferencesUi::loadImages( IN const wchar_t *pszSheet )
{
	return 0;
}

bool PreferencesUi::updatePreferences( IN const wchar_t *pszSheet, IN const wchar_t *type, IN const wchar_t *value )
{
	std::wstring LayoutUV = L"uv";
	std::wstring DoubleSided = L"doublesided";
	std::wstring ValueFalse = L"false";
	std::wstring ValueTrue = L"true";

	if(pszSheet == LayoutUV)
	{
		if(type == DoubleSided)
		{
			if(value == ValueFalse)
			{
				UVDlg->GetDlgItem(IDC_CB_UV_AREA_BACK)->EnableWindow(FALSE);
				UVDlg->GetDlgItem(IDC_PIC_UV_AREA_BACK)->EnableWindow(FALSE);
				UVDlg->GetDlgItem(IDC_CB_UV_IMAGE_BACK)->EnableWindow(FALSE);
				UVDlg->GetDlgItem(IDC_PIC_UV_IMAGE_BACK)->EnableWindow(FALSE);
				UVDlg->GetDlgItem(IDC_PB_UV_IMAGE_BACK)->EnableWindow(FALSE);
				UVDlg->GetDlgItem(IDC_CB_UV_SECOND_PAGE_BACK)->EnableWindow(FALSE);
				UVDlg->GetDlgItem(IDC_RG_UV_MAC_BACK_A)->EnableWindow(FALSE);
				UVDlg->GetDlgItem(IDC_RG_UV_MAC_BACK_B)->EnableWindow(FALSE);
			}
			else if(value == ValueTrue)
			{
				UVDlg->GetDlgItem(IDC_CB_UV_AREA_BACK)->EnableWindow(TRUE);
				UVDlg->GetDlgItem(IDC_PIC_UV_AREA_BACK)->EnableWindow(TRUE);
				UVDlg->GetDlgItem(IDC_CB_UV_IMAGE_BACK)->EnableWindow(TRUE);
				UVDlg->GetDlgItem(IDC_PIC_UV_IMAGE_BACK)->EnableWindow(TRUE);
				UVDlg->GetDlgItem(IDC_PB_UV_IMAGE_BACK)->EnableWindow(TRUE);
				UVDlg->GetDlgItem(IDC_CB_UV_SECOND_PAGE_BACK)->EnableWindow(TRUE);
				UVDlg->GetDlgItem(IDC_RG_UV_MAC_BACK_A)->EnableWindow(TRUE);
				UVDlg->GetDlgItem(IDC_RG_UV_MAC_BACK_B)->EnableWindow(TRUE);
			}
		}
	}

	return TRUE;
}

bool PreferencesUi::detectPreferencesChange( IN const wchar_t *pszSheet, IN const wchar_t *type )
{
	return TRUE;
}

bool PreferencesUi::setData( IN _PrintingPreferences *PrintingPreferences )
{
	GpUV_Preferences = PrintingPreferences;

	return TRUE;
}